package boundary;

import java.sql.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import controler.ConnectionManager;

/**
 * Servlet implementation class ListaPacotesServlet
 */
@WebServlet("/ListaPacotesServlet")
public class ListaPacotesServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public ListaPacotesServlet() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		BufferedWriter out = new BufferedWriter(new FileWriter("listapacotes.html"));
		try {
			ConnectionManager.connect("./bd");
			ResultSet listartudo = ConnectionManager.getConnection().createStatement().executeQuery("SELECT * FROM pacotes");
			
			while(listartudo.next()){
				String linha = listartudo.getInt(1) + ", " + listartudo.getBigDecimal(2) +", " + listartudo.getString(3) +", " + listartudo.getString(4)+", " + listartudo.getInt(5) + ", " + listartudo.getInt(6) +", "+ listartudo.getInt(7) +", "+ listartudo.getString(8) +", " + listartudo.getInt(9);
				out.write(linha);
				out.newLine();
			}
			out.close();
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
